﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using FirebirdSql.Data.FirebirdClient;
namespace University
{
    public partial class PEKTORAT : University.ADMINISTRATUVNI_PDROZDILU
    {
        static string sqlSelect = "SELECT * FROM PEKTORAT";
        FbDataAdapter da = new FbDataAdapter(sqlSelect, con);
        DataTable dt = new DataTable();
        public PEKTORAT(TreeNode node, ContextMenuStrip s, string com, int id)
            : base(node, s, com, id)
        {
            InitializeComponent();
            node_id = Convert.ToInt32(mynode.Tag.ToString());

            da.Fill(dt);
            bindingSource1.DataSource = dt;

            textBox5.DataBindings.Add("Text", bindingSource1, "PRORECTOR_1");
            textBox6.DataBindings.Add("Text", bindingSource1, "PRORECTOR_2");
            textBox7.DataBindings.Add("Text", bindingSource1, "PRORECTOR_3");
            textBox8.DataBindings.Add("Text", bindingSource1, "PRORECTOR_4");
            textBox9.DataBindings.Add("Text", bindingSource1, "PRORECTOR_5");
            textBox10.DataBindings.Add("Text", bindingSource1, "ZASTUPNUK_Z_PUT_GURT");

            bindingSource1.Filter = "UNIQUE_NO =" + node_id;
            if (com == "Remove") { Remove("PEKTORAT"); }
        }
        public override void Remove(string name)
        {
            base.Remove(name);
        }

        public override void UpdateForm()
        {
            OpenCon();
            UpdateFild("PEKTORAT", "PRORECTOR_1", textBox5.Text);
            UpdateFild("PEKTORAT", "PRORECTOR_2", textBox6.Text);
            UpdateFild("PEKTORAT", "PRORECTOR_3", textBox7.Text);
            UpdateFild("PEKTORAT", "PRORECTOR_4", textBox8.Text);
            UpdateFild("PEKTORAT", "PRORECTOR_5", textBox9.Text);
            UpdateFild("PEKTORAT", "ZASTUPNUK_Z_PUT_GURT", textBox10.Text);
            base.UpdateForm();

        }
        public override void InsertFild(string klas)
        {
            OpenCon();
            FbCommand cmdInsert = new FbCommand("INSERT INTO PEKTORAT(UNIQUE_NO,PRORECTOR_1,PRORECTOR_2,PRORECTOR_3,PRORECTOR_4,PRORECTOR_5,ZASTUPNUK_Z_PUT_GURT) VALUES(@1,@2,@3,@4,@5,@6,@7)", con);
            cmdInsert.Parameters.AddWithValue("1", textBox1.Text);
            cmdInsert.Parameters.AddWithValue("2", textBox5.Text);
            cmdInsert.Parameters.AddWithValue("3", textBox6.Text);
            cmdInsert.Parameters.AddWithValue("4", textBox7.Text);
            cmdInsert.Parameters.AddWithValue("5", textBox8.Text);
            cmdInsert.Parameters.AddWithValue("6", textBox9.Text);
            cmdInsert.Parameters.AddWithValue("7", textBox10.Text);
            cmdInsert.ExecuteNonQuery();
            base.InsertFild(klas);
        }

        private void PEKTORAT_Load(object sender, EventArgs e)
        {

        }
    }
}